<template>
	<div>
		<div style="">
			
			<span>人数：</span>
			<!-- <el-input style="width:150px;" v-model="peopleNumT" placeholder="请输入人数" @keydown.enter.native="select()"></el-input>&nbsp;&nbsp;-->
			 <el-select v-model="peopleNumT" style="width:150px;margin-left: 10px;" @change="select()">
			 	<el-option v-for="item in wupin" :key="item" :label="item" :value="item">
			 	</el-option>
			 </el-select>
			<span>状态：</span>
			<el-select v-model="statusT" style="width:150px;margin-left: 10px;" @change="select()">
				<el-option v-for="item in statuss" :key="item.value" :label="item.title" :value="item.id">
				</el-option>
			</el-select>&nbsp;&nbsp;&nbsp;
			<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="select">查询
			</el-button>
			<el-button style="margin:10px;" size="mini" type="primary" icon="document" @click="cleans">重置
			</el-button>&nbsp;&nbsp;
			<el-button style='margin: 10px 0;' :disabled="!isAuth('priceConfiguration:add')" size="mini" type="primary"
				icon="document" @click="addNotice">添加</el-button>
		</div>
		<el-table v-loading="tableDataLoading" :data="tableData.list">

			<el-table-column fixed prop="priceRuleId" label="编号" width="50">
			</el-table-column>
			<el-table-column prop="startNum" label="开始公里数">
			</el-table-column>
			<el-table-column prop="endNum" label="结束公里数">
			</el-table-column>
			<el-table-column prop="groupPrice" label="乘客拼座价格(元/公里)">
			</el-table-column>
			<el-table-column prop="price" label="乘客独享价格(元/公里)">
			</el-table-column>
			<!-- <el-table-column prop="driverGroupPrice" label="司机拼座收益">
			</el-table-column>
			<el-table-column prop="driverPrice" label="司机独享收益">
			</el-table-column> -->
			<el-table-column prop="peopleNum" label="人数">
			</el-table-column>
			<el-table-column prop="isEnable" label="是否启用">
				<template slot-scope="scope">
					<el-switch v-model="scope.row.status" @change="change2(scope.row.status,scope.row)"
						:active-value="openValue" :inactive-value="closeValue" active-color="#13ce66"
						inactive-color="#ff4949">
					</el-switch>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="180">
				<template slot-scope="scope">
					<el-button size="mini" type="primary" :disabled="!isAuth('priceConfiguration:update')"
						@click="amendBanner(scope.row)">修改
					</el-button>
					<el-button size="mini" type="danger" :disabled="!isAuth('priceConfiguration:delete')"
						@click="deletes(scope.row)">删除
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div style="text-align: center;margin-top: 10px;">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:page-sizes="[10, 20, 30, 50, 100]" :page-size="limit" :current-page="page"
				layout="total,sizes, prev, pager, next,jumper" :total="tableData.totalCount">
			</el-pagination>
		</div>
		<el-dialog :title="title" :visible.sync="dialogFormVisible" center>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">开始公里数：</span>
				<el-input style="width:50%;" v-model="startNum" placeholder="请输入开始公里数"></el-input>
			</div>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">结束公里数：</span>
				<el-input style="width:50%;" v-model="endNum" placeholder="请输入结束公里数"></el-input>
			</div>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">乘客拼座价格(元/公里)：</span>
				<el-input style="width:50%;" v-model="groupPrice" placeholder="请输入乘客拼座价格"></el-input>
			</div>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">乘客独享价格(元/公里)：</span>
				<el-input style="width:50%;" v-model="price" placeholder="请输入乘客独享价格"></el-input>
			</div>
			<!-- <div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">司机拼座收益：</span>
				<el-input style="width:50%;" v-model="driverGroupPrice" placeholder="请输入司机拼座收益"></el-input>
			</div>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">司机独享收益：</span>
				<el-input style="width:50%;" v-model="driverPrice" placeholder="请输入司机独享收益"></el-input>
			</div> -->
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">人数：</span>
				<el-input style="width:50%;" v-model="peopleNum" placeholder="请输入人数"></el-input>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取 消</el-button>
				<el-button type="primary" @click="addNoticeTo()">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				tableDataLoading: true,
				dialogFormVisible: false,
				tableData: [],
				num: '',
				memberImg: '',
				isEnable: 1,
				rewardProp: '',
				redPacketNum: '',
				sort: '',
				rewardId: '',
				title: '添加',
				openValue: 1,
				closeValue: 2,
				// ---
				priceRuleId:'',
				startNum: 1, //开始公里数
				endNum: 1, //结束公里数
				groupPrice: 1, //乘客拼座价格
				price: 1, //乘客独享价格
				driverGroupPrice: 1, //司机拼座收益
				driverPrice: 1, //司机独享收益
				peopleNum: 1, //人数
				status: 1, //状态 1开启 2关闭
				peopleNumT:'',
				statusT:'',
				statuss: [{
						id: '',
						title: '全部'
					},
					{
						id: 1,
						title: '启用'
					},
					{
						id: 2,
						title: '禁用'
					},
					
				],
				peopleNums:0,
				wupin:[],
				
			}
		},
		methods: {
			select(){
					this.page = 1
					this.dataSelect()
			},
			cleans(){
					this.page = 1
					this.peopleNumT = this.wupin[0]
					this.statusT = ''
					this.dataSelect()
			},
			// 获取数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({ 
					url: this.$http.adornUrl('priceRule/selectPriceRuleList'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'peopleNum':this.peopleNumT,
						'status':this.statusT,
					})
				}).then(({
					data
				}) => {
					if (data && data.code === 0) {
						console.log('会员列表', data)
						this.tableDataLoading = false
						let returnData = data.data;
						this.tableData = returnData;
						if(this.tableData.records.length==0){
							if(this.page>1){
								this.page = this.page-1
								this.dataSelect()
							}
						}
					}

				})
			},
			//上传成功
			handleAvatarSuccess(file) {
				this.memberImg = file.data
			},
			addNotice() {
				this.priceRuleId = ''
				this.startNum = ''
				this.endNum = ''
				this.groupPrice = ''
				this.price = ''
				this.driverGroupPrice = ''
				this.driverPrice = ''
				this.peopleNum = ''
				this.status = 1
				this.title = '添加'
				this.dialogFormVisible = true
			},
			handleCurrentChange(val) {
				this.page = val
				this.dataSelect()
			},
			handleSizeChange(val) {
				this.limit = val
				this.dataSelect()
			},
			// 添加banner图
			addNoticeTo() {
				if (this.startNum === '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入开始公里数',
						type: 'warning'
					});
					return
				}
				if (this.endNum === '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入结束公里数',
						type: 'warning'
					});
					return
				}
				if (this.groupPrice === '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入乘客拼座价格',
						type: 'warning'
					});
					return
				}
				if (this.price === '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入乘客独享价格',
						type: 'warning'
					});
					return
				}
				// if (this.driverGroupPrice === '') {
				// 	this.$notify({
				// 		title: '提示',
				// 		duration: 1800,
				// 		message: '请输入司机拼座收益',
				// 		type: 'warning'
				// 	});
				// 	return
				// }
				// if (this.driverPrice === '') {
				// 	this.$notify({
				// 		title: '提示',
				// 		duration: 1800,
				// 		message: '请输入司机独享收益',
				// 		type: 'warning'
				// 	});
				// 	return
				// }
				if (this.peopleNum === '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入人数',
						type: 'warning'
					});
					return
				}
				if (this.title == '添加') {
					var url = 'priceRule/insertPriceRule'
				} else {
					var url = 'priceRule/updatePriceRule'
				}
				this.$http({
					url: this.$http.adornUrl(url),
					method: 'post',
					// params: this.$http.adornParams({
					data: this.$http.adornData({
						'startNum': this.startNum,
						'endNum': this.endNum,
						'groupPrice': this.groupPrice,
						'price': this.price,
						'driverGroupPrice': this.driverGroupPrice,
						'driverPrice': this.driverPrice,
						'peopleNum': this.peopleNum,
						'status': this.status,
						'priceRuleId': this.priceRuleId,
						'driverGroupPrice': this.driverGroupPrice,
						
						
					})
				}).then(({
					data
				}) => {
					if(data.code==0){
						this.dialogFormVisible = false
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								
								this.dataSelect()
							}
						})
					}else{
						this.$message({
							message: data.msg,
							type: 'warning',
							duration: 1500,
							onClose: () => {
							}
						})
					}
					
				})
			},
			// 修改
			amendBanner(rows) {
				this.title = '修改'
				this.priceRuleId = rows.priceRuleId
				this.startNum = rows.startNum
				this.endNum = rows.endNum
				this.groupPrice = rows.groupPrice
				this.price = rows.price
				this.driverGroupPrice = rows.driverGroupPrice
				this.driverPrice = rows.driverPrice
				this.peopleNum = rows.peopleNum
				this.status = rows.status
				this.dialogFormVisible = true
			},
			//删除一级
			deletes(row) {
				let delid = row.priceRuleId
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: ''
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl('priceRule/deletePriceRule'),
						method: 'post',
						params: this.$http.adornParams({
							'priceRuleId':delid
						})
					}).then(({
						data
					}) => {
						if(data.code==0){
							this.$message({
								message: '删除成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.dataSelect()
								}
							})
						}else{
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {
								}
							})
						}
						
					})
				}).catch(() => {})
			},
			// 是否启用
			change2(val, row) {
				this.$http({
					url: this.$http.adornUrl('priceRule/updatePriceRule'),
					method: 'post',
					// params: this.$http.adornParams({
					data: this.$http.adornData({
						'startNum': row.startNum,
						'endNum': row.endNum,
						'groupPrice': row.groupPrice,
						'price': row.price,
						'driverGroupPrice': row.driverGroupPrice,
						'driverPrice': row.driverPrice,
						'peopleNum': row.peopleNum,
						'status': row.status,
						'priceRuleId': row.priceRuleId,
						'driverGroupPrice': row.driverGroupPrice,
					})
				}).then(({
					data
				}) => {
					if(data.code==0){
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.dataSelect()
							}
						})
					}else{
						this.$message({
							message: data.msg,
							type: 'warning',
							duration: 1500,
							onClose: () => {
								this.dataSelect()
							}
						})
					}
				})
			},
			// 获取物品类型获取物品类型
			xianshi() {
				this.$http({
					url: this.$http.adornUrl('common/type/426'),
					method: 'get',
					data: this.$http.adornData({})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.peopleNums = Number(data.data.value)
						
						if(this.peopleNums>0){
							var wupin =[]
							var number = 1
							for(var i=1;i <= this.peopleNums;i++){
								wupin.push(number)
								number = (i+1)
							}
							this.wupin = wupin
							this.peopleNumT = this.wupin[0]
							this.dataSelect()
							
						}
						
					}
				})
			},
		},
		mounted() {
			
			this.xianshi()
		}
	}
</script>

<style>
</style>
